﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace WebAPI.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class FilesController : ControllerBase
    {
        public FilesController(IWebHostEnvironment env)
        {
            Env = env;
        }

        public IWebHostEnvironment Env { get; }

        [HttpPost]
        public IActionResult Tu(IFormFile file)
        {
            var x = Guid.NewGuid().ToString();
            var y = Env.WebRootPath + @"\img\" + x + file.FileName;
            using(FileStream fs = System.IO.File.Create(y))
            {
                file.CopyTo(fs);
                fs.Close();
            }
            return Ok("/img/" + x + file.FileName);
        }





    }
}
